﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management.Automation;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Collections;

namespace BELT
{
    [Cmdlet("Click", "BrowserElement")]
    public class ClickBrowserElementCommand : Cmdlet
    {
        private Object _clickObject;
        [Parameter(Mandatory = true, ValueFromPipeline = true, Position=0)]
        public Object ClickObject
        {
            get
            {
                return _clickObject;
            }
            set
            {
                PSObject psObj = (PSObject)value;
                _clickObject = psObj.BaseObject;
            }
        }
        [Parameter(ValueFromPipeline = false)]
        public SwitchParameter WaitIE { set; get; }

        protected override void BeginProcessing()
        {
            base.BeginProcessing();
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            //WriteWarning(_clickObject.GetType().Name);
            Type objType = _clickObject.GetType();
            objType.InvokeMember("click", BindingFlags.InvokeMethod, null, _clickObject, null);
            if (WaitIE.IsPresent)
            {
                WaitIEBrowserCommand.Wait();
            }
        }
        protected override void EndProcessing()
        {
            base.EndProcessing();
        }
    }
}
